<style lang="scss" scoped>
</style>

<template>
  <div>
    <van-nav-bar title="评论列表" left-text="" left-arrow @click-left="router.back()">
    </van-nav-bar>
    <div
      v-for="(item, index) in reviewList"
      :key="index"
      style="padding: 15px 10px; border-bottom: 1px solid #ccc"
    >
      <div class="top" style="display: flex; align-items: center">
        <img :src="item.headPic" style="width: 40px; height: 40px; border-radius: 50%" alt="" />
        <span style="flex: 1; margin-left: 10px; font-size: 14px">{{ item.nickName }}</span>
        <span style="color: rgb(155 155 155)">{{ item.commentTime }}</span>
      </div>
      <div class="bottom" style="margin-top: 10px; font-size: 12px; color: rgb(143 143 143)">
        <p>{{ item.content }}</p>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import dayjs from 'dayjs'
import { request } from '../../axios/request'
import { useRouter, useRoute } from 'vue-router'

// 路由跳转
const route = useRoute()
const router = useRouter()

// 获取id
const doctorId = ref(route.query.id)

// 获取评论列表
const reviewList:any = ref([])
const getReview = async () => {
  await request
    .get('/api/health/user/inquiry/v1/findDoctorEvaluateList', {
      params: {
        doctorId: doctorId.value,
        page: 1,
        count: 10
      }
    })
    .then((res) => {
      let { message, result, status } = res.data
      if (status === '0000') {
        console.log(message)
        reviewList.value = result
        result.forEach((item: any, index: number) => {
          console.log(item.commentTime)
          const timestamp = item.commentTime
          const formattedDate = ref('')
          if (timestamp) {
            formattedDate.value = dayjs(timestamp).format('YYYY-MM-DD HH:mm')
          }
          result[index].commentTime = formattedDate.value
          console.log(formattedDate.value)
        })
        console.log(reviewList.value)
      }
    })
}
getReview()
</script>